| Conditions | 9 |
| Paths | 48 |
| Total Lines | 98 |
| Code Lines | 73 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | $(document).ready(function() { |
||
| 165 | function create_dialog(control, title, url) { |
||
| 166 | if ($('.midcom-workflow-dialog').length > 0) { |
||
| 167 | $('.midcom-workflow-dialog .ui-dialog-content').dialog('close'); |
||
| 168 | } |
||
| 169 | |||
| 170 | var dialog, iframe, spinner, |
||
| 171 | config = { |
||
| 172 | dialogClass: 'midcom-workflow-dialog', |
||
| 173 | buttons: [], |
||
| 174 | title: title, |
||
| 175 | height: 590, |
||
| 176 | width: 800, |
||
| 177 | close: function() { |
||
| 178 | control.removeClass('active'); |
||
| 179 | iframe.css('visibility', 'hidden'); |
||
| 180 | if (iframe[0].contentWindow) { |
||
| 181 | iframe[0].contentWindow.stop(); |
||
| 182 | } |
||
| 183 | }, |
||
| 184 | open: function() { |
||
| 185 | dialog.closest('.ui-dialog').focus(); |
||
| 186 | }}; |
||
| 187 | |||
| 188 | if (control.data('dialog-cancel-label')) { |
||
| 189 | config.buttons.push({ |
||
| 190 | text: control.data('dialog-cancel-label'), |
||
| 191 | click: function() { |
||
| 192 | $(this).dialog( "close" ); |
||
| 193 | } |
||
| 194 | }); |
||
| 195 | } |
||
| 196 | |||
| 197 | if ($('#midcom-dialog').length > 0) { |
||
| 198 | dialog = $('#midcom-dialog'); |
||
| 199 | iframe = dialog.find('> iframe'); |
||
| 200 | spinner = dialog.find('> i').show(); |
||
|
|
|||
| 201 | config.height = dialog.dialog('option', 'height'); |
||
| 202 | config.width = dialog.dialog('option', 'width'); |
||
| 203 | if ( config.width > window.innerWidth |
||
| 204 | || config.height > window.innerHeight) { |
||
| 205 | config.position = { my: "center", at: "center", of: window, collision: 'flipfit' }; |
||
| 206 | } |
||
| 207 | } else { |
||
| 208 | spinner = $('<i class="fa fa-pulse fa-spinner"></i>'); |
||
| 209 | iframe = $('<iframe name="datamanager-dialog"' |
||
| 210 | + ' frameborder="0"' |
||
| 211 | + ' marginwidth="0"' |
||
| 212 | + ' marginheight="0"' |
||
| 213 | + ' width="100%"' |
||
| 214 | + ' height="100%"' |
||
| 215 | + ' scrolling="auto" />'); |
||
| 216 | |||
| 217 | dialog = $('<div id="midcom-dialog"></div>') |
||
| 218 | .append(spinner) |
||
| 219 | .append(iframe) |
||
| 220 | .on('dialogcreate', function() { |
||
| 221 | var maximized = false, |
||
| 222 | saved_options = {}; |
||
| 223 | $(this).prevAll('.ui-dialog-titlebar').on('dblclick', function() { |
||
| 224 | if (!maximized) { |
||
| 225 | saved_options.position = dialog.dialog('option', 'position'); |
||
| 226 | saved_options.width = dialog.dialog('option', 'width'); |
||
| 227 | saved_options.height = dialog.dialog('option', 'height'); |
||
| 228 | dialog.dialog('option', { |
||
| 229 | width: '99%', |
||
| 230 | height: $(window).height(), |
||
| 231 | position: {my: 'center top', at: 'center top', of: window} |
||
| 232 | }); |
||
| 233 | maximized = true; |
||
| 234 | } else { |
||
| 235 | dialog.dialog('option', { |
||
| 236 | height: saved_options.height, |
||
| 237 | width: saved_options.width, |
||
| 238 | position: saved_options.position |
||
| 239 | }); |
||
| 240 | maximized = false; |
||
| 241 | } |
||
| 242 | }); |
||
| 243 | }) |
||
| 244 | .appendTo($('body')); |
||
| 245 | } |
||
| 246 | |||
| 247 | config.height = Math.min(config.height, window.innerHeight); |
||
| 248 | config.width = Math.min(config.width, window.innerHeight); |
||
| 249 | |||
| 250 | if (url) { |
||
| 251 | iframe.attr('src', url); |
||
| 252 | } |
||
| 253 | |||
| 254 | control.addClass('active'); |
||
| 255 | if ( control.parent().attr('role') === 'gridcell' |
||
| 256 | && control.closest('.jqgrow').hasClass('ui-state-highlight') === false) { |
||
| 257 | //todo: find out why the click doesn't bubble automatically |
||
| 258 | control.parent().trigger('click'); |
||
| 259 | } |
||
| 260 | make_dialog(dialog, config); |
||
| 261 | dialog.dialog("instance").uiDialog.draggable("option", "containment", false); |
||
| 262 | } |
||
| 263 | |||
| 278 |